package lambdasinaction.chap2;

import java.util.Arrays;
import java.util.List;

public class PrettyPrintApple {

    public static void main(String[] args) {
        prettyPrintApple(Arrays.asList(new FilteringApples.Apple(100, "green")), new AppleFancyFormatter());
        prettyPrintApple(Arrays.asList(new FilteringApples.Apple(100, "green")), new AppleFancyFormatter());
    }

    public static void prettyPrintApple(List<FilteringApples.Apple> inventory, AppleFormatter formatter) {
        inventory.forEach(apple -> {
            String output = formatter.accept(apple);
            System.out.println(output);
        });
    }


    interface AppleFormatter {
        String accept(FilteringApples.Apple apple);
    }

    static class AppleFancyFormatter implements AppleFormatter {

        @Override
        public String accept(FilteringApples.Apple apple) {
            return "A " + (apple.getWeight() > 150 ? "heavy" : "light") + " " + apple.getColor() + " apple";
        }

    }

    static class AppleSimpleFormatter implements AppleFormatter {

        @Override
        public String accept(FilteringApples.Apple apple) {
            return "An apple of " + apple.getWeight() + "g";
        }
    }

}
